<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.system.announcement.entity.titile')">
              <a-input placeholder="" v-model="queryParam.titile"></a-input>
            </a-form-item>
          </a-col>
          <!--<a-col :span="6">
            <a-form-item :label="$t('m.system.announcement.entity.msgContent')">
              <a-input placeholder="" v-model="queryParam.msgContent"></a-input>
            </a-form-item>
          </a-col>-->

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
      <a-button @click="batchDel" type="default"  icon="delete">{{ $t('m.common.button.delete') }}</a-button>
      <a-button type="default" icon="download" @click="handleExportXls('系统通告')">{{ $t('m.common.button.export') }}</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="default" icon="import">{{ $t('m.common.button.import') }}</a-button>
      </a-upload>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="serialNum" slot-scope="text,record,index">
          {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
        </template>
        <span slot="action" slot-scope="text, record">
          <a  v-if="record.sendStatus == 0" @click="handleEdit(record)">{{ $t('m.common.button.update') }}</a>

          <a-divider type="vertical" v-if="record.sendStatus == 0"/>
          <a-dropdown>
            <a class="ant-dropdown-link">{{$t('m.common.button.more')}} <ych-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="record.sendStatus != 1">
                <a-popconfirm :title="$t('m.common.tip.delete_confirm')" @confirm="() => handleDelete(record.id)">
                  <a>{{ $t('m.common.button.delete') }}</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-if="record.sendStatus == 0">
                <a-popconfirm :title="$t('m.system.announcement.verify.publish_confirm')" @confirm="() => releaseData(record.id)">
                  <a>{{$t('m.system.announcement.other.publish')}}</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-if="record.sendStatus == 1">
                <a-popconfirm :title="$t('m.system.announcement.verify.unpublish_confirm')" @confirm="() => reovkeData(record.id)">
                  <a>{{$t('m.system.announcement.other.unpublish')}}</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                  <a @click="handleDetail(record)">{{$t('m.common.title.detail')}}</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sysAnnouncement-modal ref="modalForm" @ok="modalFormOk"></sysAnnouncement-modal>
  </a-card>
</template>

<script>

  import SysAnnouncementModal from './modules/SysAnnouncementModal'
  import {doReleaseData, doReovkeData} from '@/api/api'
  import {getAction} from '@/api/manage'
  import {YcListMixin} from '@/mixins/YcListMixin'
  import YchConstant from "@/api/YchConstant";
  import LocaleUtil from "../../utils/LocaleUtil";

  export default {
    name: "SysAnnouncementList",
    mixins: [YcListMixin],
    components: {
      SysAnnouncementModal,
    },
    data() {
      return {
        description: '系统通告表管理页面',
        // 查询条件
        queryParam: {},
        // 表头
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            scopedSlots: { customRender: 'serialNum' },
          },

          {
            title: this.$t('m.system.announcement.entity.titile'),
            align: "left",
            dataIndex: 'titile',
            ellipsis: true,
          },
          {
            title: this.$t('m.system.announcement.entity.msgCategory'),
            align: "center",
            width: '120px',
            dataIndex: 'msgCategory',
            customRender: function (text) {
              if (text == '1') {
                return LocaleUtil.getLocale('m.system.announcement.other.msgCategory_option1')
              } else if (text == "2") {
                return LocaleUtil.getLocale('m.system.announcement.other.msgCategory_option2')
              } else {
                return text;
              }
            }
          },
          /*{
            title: '开始时间',
            align: "center",
            dataIndex: 'startTime'
          },
          {
            title: '结束时间',
            align: "center",
            dataIndex: 'endTime'
          },*/
          {
            title: this.$t('m.system.announcement.entity.sender'),
            align: "center",
            width: '80px',
            dataIndex: 'sender'
          },
          {
            title: this.$t('m.system.announcement.entity.priority'),
            align: "center",
            dataIndex: 'priority',
            width: '70px',
            customRender: function (text) {
              if(text=='L'){
                return LocaleUtil.getLocale('m.system.announcement.other.priority_option1')
              }else if(text=="M"){
                return LocaleUtil.getLocale('m.system.announcement.other.priority_option2')
              }else if(text=="H"){
                return LocaleUtil.getLocale('m.system.announcement.other.priority_option3')
              } else {
                return text;
              }
            }
          },
          {
            title: this.$t('m.system.announcement.entity.msgType'),
            align: "center",
            width: '130px',
            dataIndex: 'msgType',
            customRender: function (text) {
              if (text == 'USER') {
                return LocaleUtil.getLocale('m.system.announcement.other.msgType_option1')
              } else if (text == "ALL") {
                return LocaleUtil.getLocale('m.system.announcement.other.msgType_option2')
              } else {
                return text;
              }
            }
          },
          {
            title: this.$t('m.common.label.status'),
            align: "center",
            width: '100px',
            dataIndex: 'sendStatus',
            customRender: function (text) {
              if (text == 0) {
                return LocaleUtil.getLocale('m.system.announcement.other.sendStatus_option0')
              } else if (text == 1) {
                return LocaleUtil.getLocale('m.system.announcement.other.sendStatus_option1')
              } else if (text == 2) {
                return LocaleUtil.getLocale('m.system.announcement.other.sendStatus_option2')
              } else {
                return text;
              }
            }
          },
          {
            title: this.$t('m.system.announcement.entity.sendTime'),
            align: "center",
            width: '150px',
            dataIndex: 'sendTime'
          },
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: "center",
            width: '130px',
            scopedSlots: {customRender: 'action'},
          }
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + "/annountCement/list",
          delete: YchConstant.PREFIX_SYSTEM + "/annountCement/delete",
          deleteBatch: YchConstant.PREFIX_SYSTEM + "/annountCement/deleteBatch",
          releaseDataUrl: YchConstant.PREFIX_SYSTEM + "/annountCement/doReleaseData",
          reovkeDataUrl: YchConstant.PREFIX_SYSTEM + "/annountCement/doReovkeData",
          exportXlsUrl: YchConstant.PREFIX_SYSTEM + "/annountCement/exportExcel",
          importExcelUrl: YchConstant.PREFIX_SYSTEM + "/annountCement/importExcel",
        },
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${bootConfig[process.env.NODE_ENV].VUE_APP_API}${this.url.importExcelUrl}`;
      }
    },
    methods: {
      //执行发布操作
      releaseData: function (id) {
        //console.log(id);
        var that = this;
        doReleaseData({id: id}).then((res) => {
          if (res.success) {
            that.messageUtil.success(res.message);
            that.loadData(1);
          } else {
            that.messageUtil.warning(res.message);
          }
        });
      },
      //执行撤销操作
      reovkeData: function (id) {
        var that = this;
        doReovkeData({id: id}).then((res) => {
          if (res.success) {
            that.messageUtil.success(res.message);
            that.loadData(1);
            this.syncHeadNotic(id)
          } else {
            that.messageUtil.warning(res.message);
          }
        });
      },
      syncHeadNotic(anntId){
        getAction(YchConstant.PREFIX_SYSTEM + "/annountCement/syncNotic",{anntId:anntId})
      },
    }
  }
</script>
<style lang="less" scoped>

</style>
